//
//  MeSecondCell.m
//  zctx
//
//  Created by apple on 15/12/23.
//  Copyright © 2015年 sanliang. All rights reserved.
//

#import "MeSecondCell.h"

@implementation MeSecondCell

- (void)awakeFromNib {
    // Initialization code
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier andDict:(NSDictionary *)dict{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        NSArray *titleArray = [[NSArray alloc]init];
        if (dict) {
            NSString *takepart_count = [NSString stringWithFormat:@"%@",[dict objectForKey:@"redpack_count"]];
            NSString *follow_founding_count = [NSString stringWithFormat:@"%@",[dict objectForKey:@"my_takepart_count"]];
            NSString *beans = [NSString stringWithFormat:@"%@",[dict objectForKey:@"beans"]];
            BOOL isnull = [NSString isNull:takepart_count];
            if (isnull == YES) {
                titleArray = @[@"0",@"0",@"0"];
            }else{
                titleArray = @[takepart_count,follow_founding_count,beans];
            }
        }else{
            titleArray = @[@"0",@"0",@"0"];
        }
        if (UserModel.password.length==1) {
            titleArray = @[@"0",@"0",@"0"];
        }
        NSLog(@"titleArray = %@",titleArray);
        NSArray *contentArray = [NSArray arrayWithObjects:@"我的红包",@"参与的项目",@"我的健康豆",nil];
        for (int i = 0; i <titleArray.count; i++) {
            CGRect frame = CGRectMake(i*SCREEN_WIDTH/3, 0, SCREEN_WIDTH/3, 80);
            MeButton *btnView = [[MeButton alloc] initWithFrame:frame];
            btnView.title = titleArray[i];
            btnView.content = contentArray[i];
            btnView.tag = i;
            [self.contentView addSubview:btnView];
            [btnView addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
            if (i==0) {
                 btnView.titleColor = [UIColor colorWithHexString:@"#ff6847"];
            }else if (i==1){
                 btnView.titleColor = [UIColor colorWithHexString:@"#f59e11"];
            }else{
                 btnView.titleColor = [UIColor colorWithHexString:@"#4fcd3f"];
            }
            btnView.contentColor = [UIColor colorWithHexString:@"#8a8a8a"];
        }
    }
    return self;
}
-(void)buttonClick:(UIButton *)sender{
    NSInteger index = sender.tag;
    if ([_delegate respondsToSelector:@selector(didSelectMeSecondCellIndex:)]) {
        [_delegate didSelectMeSecondCellIndex:index];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
